//
//  BtnMoreAlertView.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/25.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "BtnMoreAlertView.h"

@implementation BtnMoreAlertView

- (instancetype)initBtnMoreAlertView:(UIView *)aSuperView arr:(NSArray <NSString *>*)arr  bgImgStr:(NSString *)bgImgStr
{
    if (self = [super initWithInSuperView:aSuperView]) {
        GLGWView *alerV = [[GLGWView alloc] initWithInSuperView:self];
        [alerV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.equalTo(self);
        }];
        GLGWImageView *imgV = [[GLGWImageView alloc] initInSuperView:alerV];
        imgV.image = [UIImage imageNamed:bgImgStr];
        [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(alerV);
        }];
        
        CGFloat hi;
        if ([bgImgStr isEqualToString:@"bg_gengduo"]) {
            hi = kHeightProportion_In_iPhoneTriploid(5);
        } else {
            hi = kHeightProportion_In_iPhoneTriploid(1);
        }
        GLGWButton *topBtn = [[GLGWButton alloc] initWithTitle:arr[0] titleLableFont:SYSTEMFONT(12) titleLableColor:[UIColor colorWithHexString:@"#FFFFFF"] inSuperView:alerV];
        [topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(alerV);
            make.top.equalTo(alerV.mas_top).offset(hi);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(27)));
        }];
        if ([bgImgStr isEqualToString:@"bg_gengduo"]) {
            topBtn.tag = 340;
        } else {
            topBtn.tag = 343;
        }
        [topBtn addTarget:self action:@selector(topActoin:) forControlEvents:UIControlEventTouchUpInside];
        
        GLGWView *lineV = [[GLGWView alloc] initWithInSuperView:self];
        lineV.backgroundColor = [UIColor colorWithHexString:@"#757474"];
        [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(topBtn.mas_bottom);
            make.left.right.equalTo(self);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(1)));
        }];
        
        GLGWButton *bottomBtn = [[GLGWButton alloc] initWithTitle:arr[1] titleLableFont:SYSTEMFONT(12) titleLableColor:[UIColor colorWithHexString:@"#FFFFFF"] inSuperView:alerV];
        [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(alerV);
            make.top.equalTo(lineV.mas_bottom);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(27)));
        }];
        if ([bgImgStr isEqualToString:@"bg_gengduo"]) {
            bottomBtn.tag = 343;
        } else {
            bottomBtn.tag = 340;
        }
        [bottomBtn addTarget:self action:@selector(bottomAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)topActoin:(GLGWButton *)sender
{
    if (self.BlockBtnClick) {
        self.BlockBtnClick(sender);
    }
    [self hiddenV];
}

- (void)bottomAction:(GLGWButton *)sender
{
    if (self.BlockBtnClick) {
        self.BlockBtnClick(sender);
    }
    [self hiddenV];
}

- (void)hiddenV
{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}

- (void)showV
{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    } completion:^(BOOL finished) {
        self.hidden = NO;
    }];
}

@end
